

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import webpage.SendMail;

/**
 * Servlet implementation class VerifyEmail
 */

public class VerifyEmail extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
    public VerifyEmail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String loginEmail = (String)request.getSession().getAttribute("loginEmail");
		System.out.println(loginEmail);
		String code = (int)((Math.random()*100)+1000)+"";
		String text = "Dear User,"
				+ "\n\n your verification code is "+code;
		SendMail send = new SendMail();
		String sendResult = send.sendMail(loginEmail,text);
		HttpSession session = request.getSession(true);
		session.setAttribute("sendResult", sendResult);
		session.setAttribute("code", code);
		System.out.println(session.getAttribute("code"));
		RequestDispatcher rd;
		rd= request.getRequestDispatcher("verify_email.jsp");
		rd.forward(request,response);
		
	}

}
